package com.cheng.service.takedelivery.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cheng.dao.takedelivery.PromotionDao;
import com.cheng.domain.page.PageBean;
import com.cheng.domain.takedelivery.Promotion;
import com.cheng.service.takedelivery.PromotionService;

@Service
@Transactional
public class PromotionServiceImpl implements PromotionService {
	
	@Autowired
	private PromotionDao promotionDao;

	@Override
	public Promotion getPromoationMessage(Integer id) {
		return promotionDao.findOne(id);
	}

	@Override
	public PageBean<Promotion> getPromoationByPage(Integer page,Integer rows) {
		Pageable pageable = new PageRequest(page-1,rows);
		Page<Promotion> pagedata = promotionDao.findAll(pageable);
		PageBean<Promotion> pageBean = new PageBean<Promotion>();
		pageBean.setTotalCount(pagedata.getTotalElements());
		pageBean.setPageData(pagedata.getContent());
		return pageBean;
	}

	@Override
	public void save(Promotion promotion) {
		promotionDao.save(promotion);
	}

	@Override
	public Page<Promotion> findPageData(Pageable pageable) {
		return promotionDao.findAll(pageable);
	}

	@Override
	public void updatePromotion(Date date) {
		promotionDao.updatePromotion(date);
	}

}
